home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / sharew / dfue / midi.net / midinet / midinet.asm < prev    next >
Encoding:
Assembly Source File  |  1988-04-19  |  18.0 KB  |  529 lines

  1. ********************************************************
  2. *
  3. * Installationsroutine und Interruptroutine
  4. * fuer MIDInet
  5. *
  6. * (C) 1987 by A. Buttchereit
  7. *         and G. Nowinski
  8. *             Moosholzweg 10
  9. *             3392 Clausthal-Zellerfeld 3
  10. *
  11. ********************************************************
  12.  
  13.  
  14.  
  15.  
  16. gemdos:       EQU           $01
  17. bios:         EQU           $0d
  18. xbios:        EQU           $0e
  19.  
  20. start:  
  21.               move.l        4(sp),a0
  22.               add.l         #$86,a0
  23.               clr.l         d0
  24.               move.b        #6,d1       ;Zaehler
  25. l1:           asl.l         #4,d0
  26.               and.b         #$0f,-(a0)
  27.               or.b          (a0),d0             ;Wiederherstellen
  28.               subq.b        #1,d1
  29.               bne           l1
  30.  
  31.  
  32.               move.l        d0,nummer_adr   ;Adresse berechnet
  33.  
  34.               addq.l        #2,d0
  35.               move.l        d0,send_adr     ;Adresse des Sendreq
  36.  
  37.               addq.l        #2,d0
  38.               move.l        d0,recei_adr    ;Adresse des receivereq
  39.  
  40.               addq.l        #2,d0
  41.               move.l        d0,busy_adr     ;Adresse des busy-Flags
  42.  
  43.               addq.l        #2,d0
  44.               move.l        d0,auto_ack    ;Adresse des auto_ack-Flags
  45.  
  46.               addq.l        #2,d0
  47.               move.l        d0,ok_adr       ;Adresse des OK-Flags
  48.  
  49.               addq.l        #2,d0
  50.               move.l        d0,ack_adr      ;Adresse des Ack-Feldes
  51.  
  52.               add.l         #30,d0
  53.               move.l        d0,online_adr   ;Adresse des Online-Feldes
  54.  
  55.               add.l         #30,d0
  56.               move.l        d0,in_adr       ;Adresse des Eingabepuffers
  57.  
  58.               add.l         #128,d0
  59.               move.l        d0,out_adr      ;Adresse des Ausgabepuffers
  60.  
  61.               move          #2,-(sp)
  62.               move          #14,-(sp)
  63.               trap          #xbios  
  64.               addq.l        #4,sp
  65.  
  66.               move.l        d0,a0
  67.               move.l        (a0),mpuf_adr   ;Adresse des MIDI-puffers
  68.  
  69.               addq.l        #6,d0
  70.               move.l        d0,hd_adr       ;Adresse des Headindexes
  71.  
  72.               addq.l        #2,d0
  73.               move.l        d0,tl_adr       ;Adresse des Tailindexes
  74.  
  75.               move.l        #continue,d0
  76.               move.l        d0,adresse      ;VBI 'richtig' starten
  77.  
  78.               move.l        4(sp),a6        ;Länge des Prgs berechnen
  79.               move.l        #$100,d6
  80.               add.l         12(a6),d6
  81.               add.l         20(a6),d6
  82.               add.l         28(a6),d6
  83.  
  84.               jsr           super_ein
  85.  
  86.               move.w        $454,d0         ;freien VBI-Vektor suchen
  87.               lsl           #2,d0
  88.               move.l        $456,a0
  89.               clr.l         d1
  90. vbltest:      
  91.               tst.l         0(a0,d1.l)
  92.               beq           vblfound
  93.               addq.l        #4,d1
  94.               cmp           d0,d1
  95.               bne           vbltest
  96.         
  97. *---------------------------------------------*
  98. *    Installation hat nicht geklappt          *
  99. *---------------------------------------------*
  100.               jsr           super_aus
  101.               move.l        (sp)+,d0
  102.               move          #0,-(sp)
  103.               trap          #gemdos
  104. *---------------------------------------------*
  105. *         Freie Adresse gefunden              *
  106. *---------------------------------------------*
  107. vblfound:
  108.               lea           0(a0,d1.l),a2  ;dieses Prg eintragen    
  109.               move.l        #meinprog,(a2)
  110.               jsr           super_aus
  111. *---------------------------------------------*
  112. * Programm resident im Speicher hinterlassen  *
  113.  
  114. *---------------------------------------------*
  115.               clr.l         -(sp)
  116.               move.l        d6,-(sp)
  117.               move          #$31,-(sp)
  118.               trap          #gemdos
  119. *---------------------------------------------*
  120. *    Supervisor-Modus einschalten             *
  121. *---------------------------------------------*
  122. super_ein:   
  123.               clr.l         -(sp)
  124.               move          #32,-(sp)
  125.               trap          #gemdos
  126.               addq.l        #6,sp
  127.               move.l        d0,oldstack
  128.               rts
  129. *---------------------------------------------*
  130. *     Supervisor-Modus ausschalten            *
  131. *---------------------------------------------*
  132. super_aus:
  133.               move.l        oldstack,-(sp)
  134.               move          #32,-(sp)
  135.               trap          #gemdos
  136.               addq.l        #6,sp
  137.               rts
  138. *************************************************************************
  139.  
  140. oldstack:     DS.l          1
  141.  
  142. nummer_adr:   DS.l          1
  143. send_adr:     DS.l          1
  144. recei_adr:    DS.l          1
  145. busy_adr:     DS.l          1
  146. auto_ack:    DS.l          1
  147. ok_adr:       DS.l          1
  148. ack_adr:      DS.l          1
  149. online_adr:   DS.l          1
  150. in_adr:       DS.l          1
  151. out_adr:      DS.l          1
  152.  
  153. mpuf_adr:     DS.l          1
  154. hd_adr:       DS.l          1
  155. tl_adr:       DS.l          1
  156.  
  157. adresse:      DS.l          1
  158. kennung:      DS.w          1
  159. laenge:       DS.w          1
  160. zaehler:      DS.w          1
  161. adressat:     DS.w          1
  162. absender:     DS.w          1
  163. checksum:     DS.w          1
  164. *************************************************************************
  165. ***********************     Mein Programm     ***************************
  166. *************************************************************************
  167.  
  168. meinprog:
  169.               movem.l       a0-a2/d0-d2,-(sp)
  170.  
  171.               move.l        adresse,a0
  172.               jmp           (a0)
  173.                                             
  174. continue:                          
  175.               bsr           MIDI_in
  176.               bne           cont1
  177.               move.l        #continue,adresse
  178.               bra           B_exit
  179.  
  180. cont1: 
  181.  
  182.                                             
  183.               cmp           #0,d1         
  184.               bne           kein_freiz      ;*    zur Blockbehandlung    *
  185.               
  186. freizeichen:  
  187.               move.l        busy_adr,a0     ;*   Aktion auf Bus merken!  *
  188.               move          #1,(a0)           
  189.               move.l        send_adr,a0      
  190.               cmp           #0,(a0)          ;**************************** 
  191.               beq           kein_sendreq     ;*Wenn send_req, dann senden*
  192.               bra           senden           ;****************************
  193.               
  194. kein_sendreq: 
  195.               bsr           sende_frei       
  196.               bra           N_exit           ;*  Sonst Frei weitergeben! * 
  197.                                              
  198. kein_freiz:
  199.               move          d1,kennung
  200.               and           #$f,d1
  201.               move          d1,adressat
  202.               move          kennung,d1
  203.               lsr           #4,d1
  204.               and           #$f,d1
  205.               move          d1,absender
  206.  
  207. wie_lang:
  208.               bsr           MIDI_in
  209.               bne           cont2
  210.               move.l        #wie_lang,adresse
  211.               bra           B_exit
  212.  
  213. cont2:
  214.               move          d1,laenge
  215.               move.l        busy_adr,a0     ;*   Aktion auf Bus merken!  *
  216.               move          #1,(a0)   
  217.  
  218.               move.l        nummer_adr,a0
  219.               move          adressat,d0      ;****************************
  220.               cmp           (a0),d0          ;*Sind die Daten fuer mich? *
  221.               bne           not_for_me       ;****************************
  222.  
  223. for_me:
  224.               move          laenge,d1
  225.               cmp           #0,d1            ;*   Länge=0 ?   *                                 
  226.               bne           kein_ack   
  227.               
  228. acknol:              
  229.               move          absender,d0       
  230.               subq          #1,d0           
  231.               lsl           #1,d0           ;*****************************
  232.               move.l        ack_adr,a0      ;*      Acknol. merken!      *
  233.               move          #1,0(a0,d0.w)   ;*****************************
  234.  
  235.               move.l        busy_adr,a0
  236.               move          #0,(a0)         ;* Busy noch zurueckhalten *
  237. wait_ok:
  238.               bsr           MIDI_in
  239.               bne           setze_ok_flag
  240.               move.l        #wait_ok,adresse
  241.               bra           B_exit
  242.  
  243. setze_ok_flag:
  244.               move.l        ok_adr,a0
  245.               move          d1,(a0)
  246.  
  247.               move.l        busy_adr,a0
  248.               move          #1,(a0)         ;* aber jetzt busy *
  249.  
  250.               bra           N_exit          ;Block fertig
  251.               
  252. kein_ack:     
  253.               move.l        recei_adr,a0
  254.               cmp           #0,(a0)
  255.               beq           uebernehmen
  256.  
  257. kein_platz:              
  258.               bra           WOM   
  259.  
  260. not_for_me:
  261.               move          absender,d0     ;*****************************
  262.               move.l        nummer_adr,a0   ;*    Bin ich der Absender?  *
  263.               cmp           (a0),d0         ;*****************************
  264.               bne           MIDI_durch
  265.  
  266. from_me:
  267.               bra           WOM1
  268.  
  269. ************************************************************************
  270. ******************      KEIN ... PLATZ ... WOM      ********************
  271. WOM:
  272.               clr           zaehler
  273.  
  274.               move          laenge,d0
  275.               addq          #1,d0            ;* Laenge+1 fuer Checksum *
  276.               move          d0,laenge
  277.  
  278. Block_WOM:
  279.               bsr           MIDI_in
  280.               bne           cont3
  281.               move.l        #Block_WOM,adresse            
  282.               bra           B_exit 
  283. cont3: 
  284.               move          zaehler,d0
  285.               addq          #1,d0
  286.               move          d0,zaehler
  287.               cmp           laenge,d0 
  288.               bne           Block_WOM
  289.               
  290.               bsr           sende_frei       ;*   Freiz. ohne Acknol.   *
  291.               bra           N_exit
  292.  
  293.  
  294. ************************************************************************
  295. ******************      NOT ... ONLINE ... WOM      ********************
  296. WOM1:
  297.               move          adressat,d0     
  298.               subq          #1,d0           ;***************************
  299.               lsl           #1,d0           ;*                         *
  300.               move.l        online_adr,a0   ;*   Muell vergessen &     *
  301.               move          #0,0(a0,d0.w)   ;*   Adressat streichen!   *
  302.                                             
  303.               clr           zaehler
  304.  
  305.               move          laenge,d0
  306.               addq          #1,d0            ;* Laenge+1 fuer Checksum *
  307.               move          d0,laenge
  308.  
  309. Block_WOM1:
  310.               bsr           MIDI_in
  311.               bne           cont4
  312.               move.l        #Block_WOM1,adresse            
  313.               bra           B_exit 
  314. cont4: 
  315.               move          zaehler,d0
  316.               addq          #1,d0
  317.               move          d0,zaehler
  318.               cmp           laenge,d0 
  319.               bne           Block_WOM1
  320.  
  321.               bsr           sende_frei
  322.               bra           N_exit            
  323.  
  324. ***********************************************************************
  325. *********     Ein Zeichen von der MIDIschnittstelle lesen    **********
  326. MIDI_in:
  327.               move.l        hd_adr,a1        ;****************************                                                    
  328.               move          (a1)+,d0  ;head   *     Ist ein Zeichen      *     
  329.               cmp           (a1),d0   ;tail   *        im Puffer ?       *
  330.               bne           Zeichen          ;****************************
  331.               rts
  332. Zeichen: 
  333.               addq          #1,d0            
  334.               and           #$7f,d0         
  335.               move.l        mpuf_adr,a0     
  336.               move.b        0(a0,d0.w),d1    ;Zeichen nach D1!
  337.               and           #$ff,d1    
  338.               move          d0,-(a1)         ;head setzen
  339.               move          #1,d0
  340.               cmp           #0,d0
  341.               rts
  342.  
  343.  
  344.  
  345. **************************************************************************
  346.  
  347. sende_frei:
  348.               move          #0,d1
  349.               jsr           MIDI_out
  350.               rts
  351.  
  352. *************************************************************************
  353.  
  354.  
  355. MIDI_out:     lea           $FFFC04,A1      ;Adresse des MIDI-Chips
  356. midiloop:     move.b        0(a1),d2
  357.               btst          #1,d2
  358.               beq           midiloop
  359.               move.b        d1,2(a1)
  360.               rts
  361. *************************************************************************
  362.  
  363. *************************************************************************
  364. *********     Senderoutine schreibt einen Block ins Netz     ************
  365.          
  366. senden:       
  367.               move          #0,checksum
  368.  
  369.               move.l        out_adr,a0
  370.               move.b        (a0),d1     ;Adresse
  371.               jsr           MIDI_out
  372.               move.b        1(a0),d1    ;Länge
  373.               and           #$ff,d1
  374.               move          d1,laenge
  375.               jsr           MIDI_out
  376.               clr           d0
  377.  
  378. loop:
  379.               cmp           laenge,d0
  380.               beq            raus
  381.               move.b        2(a0,d0.w),d1  ;Daten
  382.               move          checksum,d2
  383.               eor           d1,d2
  384.               move          d2,checksum
  385.               jsr           MIDI_out
  386.               addq          #1,d0
  387.               bra           loop
  388.  
  389. raus:
  390.               move          checksum,d1
  391.               jsr           MIDI_out
  392.  
  393.               move.l        send_adr,a0
  394.               clr           (a0)              
  395.               bra           N_exit              ;Block geschrieben
  396.               
  397. *************************************************************************                     
  398.  
  399.  
  400. *************************************************************************
  401. *********  Routine uebernimmt einen Block in den Eingabepuffer  *********
  402.  
  403. uebernehmen:
  404.               move          #0,checksum
  405.  
  406.               move.l        nummer_adr,a0
  407.               move          absender,d0
  408.               cmp           (a0),d0          ;Nachr. von mir an mich ?
  409.               bne           normal
  410.  
  411.               move.l        busy_adr,a0
  412.               move          #0,(a0)          ;Dann noch kein busy !
  413. normal:
  414.               move.l        in_adr,a0
  415.               move          kennung,d1
  416.               move.b        d1,(a0)          ;erstes Byte
  417.               move          laenge,d1
  418.               move.b        d1,1(a0)         ;Länge
  419.               clr           zaehler
  420. block_ein:
  421.               bsr           MIDI_in
  422.               bne           cont5
  423.               move.l        #block_ein,adresse            
  424.               bra           B_exit 
  425. cont5: 
  426.               move          checksum,d2
  427.               eor           d1,d2
  428.               move          d2,checksum
  429.  
  430.               move.l        in_adr,a0
  431.               move          zaehler,d0
  432.               move.b        d1,2(a0,d0.w)
  433.               addq          #1,d0
  434.               move          d0,zaehler
  435.               cmp           laenge,d0 
  436.               bne           block_ein
  437.  
  438. warte_test:
  439.               bsr           MIDI_in
  440.               bne           testen
  441.               move.l        #warte_test,adresse
  442.               bra           B_exit
  443.  
  444. testen:
  445.               move          checksum,d2
  446.               cmp           d2,d1
  447.               beq           no_io_error
  448. io_error:
  449.  
  450.               move          adressat,d1
  451.               lsl           #4,d1
  452.               add           absender,d1      ;* sende Acknol. an Absender *
  453.               jsr           MIDI_out
  454.               move          #0,d1
  455.               jsr           MIDI_out
  456.               move          #0,d1
  457.               jsr           MIDI_out
  458.               bsr           sende_frei
  459.               bra           N_exit
  460.  
  461. no_io_error:
  462.               move.l        auto_ack,a0
  463.               move          (a0),d0
  464.               cmp           #0,d0            ;* kein Auto-Acknol. ? *
  465.               beq           no_auto_ack
  466.  
  467.               move          adressat,d1
  468.               lsl           #4,d1
  469.               add           absender,d1      ;* sende Acknol. an Absender *
  470.               jsr           MIDI_out
  471.               move          #0,d1
  472.               jsr           MIDI_out 
  473.  
  474.               move          #1,d1
  475.               jsr           MIDI_out
  476.  
  477.               bsr           sende_frei
  478.  
  479. no_auto_ack:         
  480.               move.l        recei_adr,a0
  481.               move          #1,(a0)
  482.                
  483.               bra           N_exit
  484.  
  485. *************************************************************************
  486.  
  487.  
  488. *************************************************************************
  489. ***********    Weiterschicken eines Blockes ueber das Netz   ************
  490.  
  491. MIDI_durch:
  492.               move          kennung,d1
  493.               jsr           MIDI_out
  494.               move          laenge,d1
  495.               jsr           MIDI_out
  496.  
  497.               addq          #1,d1
  498.               move          d1,laenge         ;* Laenge+1 fuer checksum *
  499.  
  500.               clr           zaehler
  501.  
  502. block_durch:
  503.               move          zaehler,d0
  504.               cmp           laenge,d0
  505.               beq           N_exit
  506.          
  507.               bsr           MIDI_in
  508.               bne           cont6           
  509.               move.l        #block_durch,adresse            
  510.               bra           B_exit 
  511. cont6: 
  512.               jsr           MIDI_out
  513.               move          zaehler,d0
  514.               addq          #1,d0
  515.               move          d0,zaehler
  516.               bra           block_durch
  517.  
  518.  
  519. *************************************************************************
  520.      
  521.                            
  522. N_exit:       move.l        #continue,adresse
  523.  
  524. B_exit: 
  525.               movem.l       (sp)+,a0-a2/d0-d2
  526.               rts
  527.  
  528. *************************************************************************
  529.